package l1j.server.server.templates;

import l1j.server.server.datatables.ItemTable;
import l1j.server.server.utils.Random;


public class L1Decompose {

	private int _itemid;
	private int _chance;
	private int _mincount;
	private int _range;

	public boolean setItemId(final int id){
		if(ItemTable.getInstance().getTemplate(id) == null){
			return false;
		}
		_itemid = id;
		return true;
	}
	public void setChance(final int chance){
		_chance = (100-chance);
	}

	public void setMinCount(final int count){
		_mincount = count;
	}

	public void setMaxCount(final int count){
		if(count >0){
			_range = Math.max(0, count - _mincount);
		}
	}

	public int getItem(final int rate){
		if(rate >_chance){
			return _itemid;
		}
		return 0;
	}

	public int getCount(){
		if(_range >0){
			return Random.nextInt(_range)+_mincount;
		}
		return _mincount;
	}
}
